home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 176-200 / disk_179 / launch / launch.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  95 lines

  1. #include <libraries/dosextens.h>
  2. #include <exec/ports.h>
  3. #include <workbench/startup.h>
  4. #include <workbench/workbench.h>
  5. #include <stdio.h>
  6.  
  7. struct MsgPort *FindPort(), *CreatePort();
  8. struct WBStartup *Launch(), *GetMsg();
  9. struct Process *FindTask();
  10.  
  11. main(ac, av)
  12. int ac;
  13. char **av;
  14. {
  15.     struct MsgPort *rport;
  16.     struct Process *me;
  17.     struct CommandLineInterface *cli;
  18.     struct WBStartup *startup;
  19.  
  20.     long stack;
  21.     int pri;
  22.     char *win;
  23.     int wait;
  24.     int got_arg;
  25.  
  26.     stack = 0;
  27.     pri = 0;
  28.     win = 0;
  29.     wait = 0;
  30.  
  31.     if(ac < 2 || strcmp(av[1], "?") == 0) {
  32.         fprintf(stderr,
  33. "launch [stack nnnn] [window name] [priority PRI] [wait] program [arguments]\n"
  34.             );
  35.         exit((ac<2)?5:0);
  36.     }
  37.     got_arg = 1;
  38.     while(got_arg == 1 && ac >= 3) {
  39.         got_arg = 0;
  40.         if(dictcmp(av[1], "window") == 0) {
  41.             win = av[2];
  42.             av += 2;
  43.             ac -= 2;
  44.             got_arg = 1;
  45.         } else if(dictcmp(av[1], "stack") == 0) {
  46.             stack = atol(av[2]);
  47.             av += 2;
  48.             ac -= 2;
  49.             got_arg = 1;
  50.         } else if(dictcmp(av[1], "priority") == 0) {
  51.             pri = atoi(av[2]);
  52.             av += 2;
  53.             ac -= 2;
  54.             got_arg = 1;
  55.         } else if(dictcmp(av[1], "wait") == 0) {
  56.             wait = 1;
  57.             av ++;
  58.             ac --;
  59.             got_arg = 1;
  60.         }
  61.     }
  62.  
  63.     if(wait == 0) {
  64.         if(!(rport = FindPort("Workbench.Cleanup"))) {
  65.             fprintf(stderr, "Could not find Workbench.Cleanup port.\n");
  66.             fprintf(stderr, "Are you sure you ran wbcleanup?\n");
  67.             exit(20);
  68.         }
  69.     } else {
  70.         if(!(rport = CreatePort(0, 0))) {
  71.             printf("Can't create reply port.\n");
  72.             exit(20);
  73.         }
  74.     }
  75.     if(stack == 0) {
  76.         me = FindTask(0);
  77.         if(me->pr_CLI) {
  78.             cli = (struct CommandLineInterface *)(me->pr_CLI<<2);
  79.             stack = cli->cli_DefaultStack<<2; /* DefaultStack is in Longwords */
  80.         } else
  81.             stack = me->pr_StackSize;
  82.     }
  83.     if(!Launch(rport, av[1], &av[1], ac-1, pri, win, stack)) {
  84.         fprintf(stderr, "Could not launch %s error %d\n", av[1], IoErr());
  85.         exit(20);
  86.     }
  87.     if(wait != 0) {
  88.         WaitPort(rport);
  89.         startup = GetMsg(rport);
  90.         FreeStartup(startup);
  91.         DeletePort(rport);
  92.     }
  93.     exit(0);
  94. }
  95.